package com.simba.server.commands.impl.update;

import java.util.List;
import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class RenewPacketOffSyncCmd implements ICommand
{
	public static final String NAME = "RenewPacketOffSyncCmd";
	private final List<Integer> idList;
	private String sql = "update tt_packet_off_info set syncFlag=1 ";

	public RenewPacketOffSyncCmd(List<Integer> idList)
	{
		this.idList = idList;
	}

	@Override
	public String getName()
	{
		return RenewPacketOffSyncCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		if (idList == null || idList.size() < 1)
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			StringBuilder list = new StringBuilder();
			boolean isFirst = true;
			for (Integer id : idList)
			{
				if (isFirst)
				{
					isFirst = false;
				}
				else
				{
					list.append(",");
				}
				list.append(id);
			}
			sql += "where id in (" + list.toString() + ")";
			dbOperator.prepareStatement(this.sql);
			int rs = dbOperator.executeUpdate();

			if (rs > 0)
			{
				ret = true;
			}
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}
}
